﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 考核二
{
    
    public partial class Form2 : Form
    {
        int flag = 0;
        public Form2()
        {
            InitializeComponent();
        }


        private void 点ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            flag = 1;
        }
        List<Point> lp = new List<Point>();
        List<line> ll = new List<line>();
        line templine = new line();

        private void 点ToolStripMenuItem_MouseDown(object sender, MouseEventArgs e)
        {
            //if(flag==1)
            //{
            //    Point pt = new Point();
            //    pt.X = e.X;
            //    pt.Y = e.Y;
            //    lp.Add(pt);
            //    Invalidate();
            //}
        }

        private void 点ToolStripMenuItem_Paint(object sender, PaintEventArgs e)
        {
            
            
        }

        private void Form2_Paint(object sender, PaintEventArgs e)
        {
            if (flag == 1)
            {
                Graphics g = e.Graphics;
                SolidBrush sb = new SolidBrush(Color.Black);
                foreach (Point pt in lp)
                {
                    g.FillEllipse(sb, pt.X, pt.Y, 4, 4);
                }
                sb.Dispose();
                g.Dispose();
            }
            if (flag == 2)
            {
                Graphics g = e.Graphics;
                Pen pen = new Pen(Color.Black, 4);
                foreach(line l in ll)
                {
                    g.DrawLine(pen, l.star.X, l.star.Y, l.end.X, l.end.Y);
                }
                pen.Dispose();
                g.Dispose();
            }
        }

        private void Form2_MouseDown(object sender, MouseEventArgs e)
        {
            if (flag == 1)
            {
                Point pt = new Point();
                pt.X = e.X;
                pt.Y = e.Y;
                lp.Add(pt);
                Invalidate();
            }
            if (flag == 2)
            {
                templine.star.X = e.X;
                templine.star.Y = e.Y;
                ll.Add(templine);
                //Invalidate();
            }
        }
        public class line
        {
            public Point star;
            public Point end;
            public line()
            {
                star = new Point();
                end = new Point();
            }
        }

        private void 线ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            flag = 2;
        }

        private void Form2_MouseUp(object sender, MouseEventArgs e)
        {
            if (flag == 2)
            {
                templine.end.X = e.X;
                templine.end.Y = e.Y;
                ll.Add(templine);
                Invalidate();
                templine = new line();
            }
        }
    }
}
